package com.system.shiro.credentials;


import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
import org.apache.shiro.web.servlet.ShiroHttpServletResponse;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;

public class MyshiroHttpServletResponse extends ShiroHttpServletResponse {

	public MyshiroHttpServletResponse(HttpServletResponse wrapped,
			ServletContext context, ShiroHttpServletRequest request) {
		super(wrapped, context, request);
		
	}
	//解决url JSESSIONID的后缀
	@Override
	protected String toEncoded(String url, String sessionId) {
		 if ((url == null) || (sessionId == null))
	            return (url);

	        String path = url;
	        String query = "";
	        String anchor = "";
	        int question = url.indexOf('?');
	        if (question >= 0) {
	            path = url.substring(0, question);
	            query = url.substring(question);
	        }
	        int pound = path.indexOf('#');
	        if (pound >= 0) {
	            anchor = path.substring(pound);
	            path = path.substring(0, pound);
	        }
	        StringBuilder sb = new StringBuilder(path);
	        /*if (sb.length() > 0) { // session id param can't be first.
	            sb.append(";");
	            sb.append(DEFAULT_SESSION_ID_PARAMETER_NAME);
	            sb.append("=");
	            sb.append(sessionId);
	        }*/
	        sb.append(anchor);
	        sb.append(query);
	        return (sb.toString());
	}

}
